package cn.wolfcode.wms.web.controller;

import cn.wolfcode.wms.service.IEmployeeService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private IEmployeeService employeeService;
    @RequestMapping("login")
    @ResponseBody
    public Object login (String username, String password, HttpServletRequest req){
        JSONResult result = new JSONResult();
        String encoder = MD5.encoder(password);
        try {
          employeeService.selectInfo(username,encoder);
        } catch (Exception e) {
            e.printStackTrace();

            //表示没有验证成功
            result.mark(e.getMessage());
        return result;
        }
        return result;
    }
    @RequestMapping("main")
    public String main (){
        return "main";
    }

    @RequestMapping("logout")
    public String logout (HttpSession session){
        session.invalidate();
        return "redirect:/login.html";
    }


}
